<?php
class prepare_process{ 
	
	// Sử lý trước khi save xuống database 
	
	function prepareSave(&$row){  
		$file = new stwupload();
		$image = JRequest::getVar('image',null,'files','array');  
		if($file->prepareUpload($image)){
			if($image_name = $file->upload($image,true,400,550)){   
				$row->image = $image_name;
				$old_file = JRequest::getVar('oldimage');
				$file->deleteImage($old_file);
			}
		}
		
		/*$image1 = JRequest::getVar('image1',null,'files','array');
		
		if($file->prepareUpload($image1)){
			if($image1_name = $file->upload($image1,true,400,550)){
				$row->image1= $image1_name;	
				$old_file=JRequest::getVar('oldimage1');
				$file->deleteImage($old_file);
			}	
			
		}
		$image2 = JRequest::getVar('image2',null,'files','array');
		if($file->prepareUpload($image2)){
			if($image2_name = $file->upload($image2,true,400,550)){
				$row->image2 = $image2_name;
				$old_file = JRequest::getVar('oldimage2');
				$file->deleteImage($old_file);
			}
		}
		$image3 = JRequest::getVar('image3',null,'files','array');
		if($file->prepareUpload($image3)){
			if($image3_name = $file->upload($image3,true,400,550)){
				$row->image3 = $image3_name;
				$old_file = JRequest::getVar('oldimage3');
				$file->deleteImage($old_file);
			}
		}
		$image4 = JRequest::getVar('image4',null,'files','array');
		if($file->prepareUpload($image4)){
			if($image4_name = $file->upload($image4,true,400,550)){
				$row->image4 = $image4_name;
				$old_file = JRequest::getVar('oldimage4');
				$file->deleteImage($old_file);
			}
		}*/
		if($row->product_id==0){
			$row->created = date( 'Y-m-d H:i:s');
			//number_format($row->price);
		}
		//svae editor
		$row->description = JRequest::getVar( 'description', '', 'post','string', JREQUEST_ALLOWRAW );
		//$row->danhgia = JRequest::getVar('danhgia', '', 'post','string', JREQUEST_ALLOWRAW);
		//.end
	}
	
	//sử lý trước khi xóa sản phẩm
	function prepareDelete(&$row){
		
		$file = new stwupload();
		$file->deleteImage($row->image);
		/*$file->deleteImage($row->image1);
		$file->deleteImage($row->image2);
		$file->deleteImage($row->image3);	*/
	}
	//sử lý trước khi load dữ liệu
	function  prepareLoad(&$data){
		
		
	}
	
}